<?php
/*
 * Renvoie la collection du joueur
 */

// Vérification du joueur connecté
if(!isset($_SESSION['playerId'])){
	throw new Exception('Merci de vous authentifier.', HTTP_UNAUTHORIZED);
}
if(lockPlayer($_SESSION['playerId']))
{
	$playerDeck = loadPlayer($_SESSION['playerId']);
	
	// Initialisation de la collection de carte si vide
	if(!$playerDeck){
		$deck = getRandomDeck(NB_INIT_CARDS, $cardCollection);
		$playerDeck = array('deck' => $deck, 'id' => $_SESSION['playerId']);
		savePlayer($playerDeck);
	}
	
	if(is_array($playerDeck['deck'])){
		sort($playerDeck['deck']);
	}
	$playerDeck['number'] = (CELL * CELL)/2;
	
	echo json_encode($playerDeck);
}